//
//  PDMainMenuHeadCollectView.m
//  Pudding
//
//  Created by baxiang on 16/9/24.
//  Copyright © 2016年 Zhi Kuiyu. All rights reserved.
//

#import "PDMainMenuHeadCollectView.h"

@interface PDMainMenuHeadCollectView()<UIGestureRecognizerDelegate>
@property(nonatomic,weak) UILabel *titleLabel;
@property(nonatomic,weak) UIImageView *titleIcon;
@property(nonatomic,weak) UIButton *moreBtn;
@end
@implementation PDMainMenuHeadCollectView
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        UIImageView  *titleIcon = [UIImageView new];
        [self addSubview:titleIcon];
        titleIcon.contentMode = UIViewContentModeScaleAspectFit;
        titleIcon.image = [UIImage imageNamed:@"hp_icon_default_small"];
        
        self.titleIcon = titleIcon;
        UILabel *titleLabel = [UILabel new];
        [self addSubview:titleLabel];
        titleLabel.textColor = UIColorHex(0x4a4a4a);
        titleLabel.font = [UIFont systemFontOfSize:17];
        self.titleLabel = titleLabel;
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(titleIcon.mas_right).offset(5);
            make.top.bottom.mas_equalTo(0);
            //make.height.mas_equalTo(20);
        }];
        
        [titleIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.mas_equalTo(titleLabel.mas_top);
            make.width.mas_equalTo(15);
            make.centerY.mas_equalTo(titleLabel.mas_centerY);
        }];
        
        UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:moreBtn];
        [moreBtn setImage:[UIImage imageNamed:@"hp_icon_more"] forState:UIControlStateNormal];
        [moreBtn setTitleColor:UIColorHex(0x9b9b9b) forState:UIControlStateNormal];
        moreBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_equalTo(0);
            make.right.mas_equalTo(-5);
            make.width.mas_equalTo(@(46));
        }];
        self.moreBtn = moreBtn;
        [moreBtn addTarget:self action:@selector(moreContentHandle) forControlEvents:UIControlEventTouchUpInside];
        UITapGestureRecognizer *moreTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(moreContentHandle)];
        [self addGestureRecognizer:moreTap];
    }
    return self;
}



-(void)moreContentHandle{
    if (_moreContentBlock) {
        _moreContentBlock(_categoryModel);
    }
}
-(void)setCategoryModel:(RBCategoryModel *)categoryModel
{
    _categoryModel = categoryModel;
    self.titleLabel.text = categoryModel.title;
    [self.titleIcon yy_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",categoryModel.icon]] placeholder:nil];
}

@end

